package com.example;

import com.example.DBUtil.DBConnection;
import com.example.Utils.DownloadUtils;
import com.example.constant.sysConstant;

import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class tujidao {
    public static void main(String[] args) {

         try (Connection conn = DBConnection.getConnection(sysConstant.DRIVER,sysConstant.DBURL,sysConstant.USERNAME,sysConstant.PASSWORD);){
             ResultSet rs =  conn.prepareStatement("select numbering,name,quantity from t_atlas limit 0,1").executeQuery();
             List<Map<String,Object>> listMap = new ArrayList<>();
             while (rs.next()){
                listMap.add(DBConnection.getResultMap(rs));
             }
             StringBuffer stringBuffer = null;
             for (int i = 0; i < listMap.size(); i++) {
                 int number = Integer.parseInt(listMap.get(i).get("quantity")+"");//图片页数
                 String numbering = listMap.get(i).get("numbering")+"";//图集上层编号
                 String name = listMap.get(i).get("name")+"";//图集名称
                 for (int i1 = 0; i1 < number; i1++) {
                     stringBuffer = new StringBuffer();
                     stringBuffer.append(sysConstant.IMG_PATH_TOP).append("/").append(numbering).append("/");
                     stringBuffer.append(i1+1).append(sysConstant.JPG);
                     System.out.println("拼装图片路径为: " +stringBuffer.toString());
                     System.out.println("图片名称为: " + name);
                     System.out.println("文件存储路径为: " +  sysConstant.DOWNLOAD_PATH+ File.separator+name);
                     DownloadUtils.downloadPicture(stringBuffer.toString(),(i1+1)+"",sysConstant.DOWNLOAD_PATH+ File.separator+name);
                 }
             }









        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
